<?php


abstract class BaseBannerItem extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $user_id;


	
	protected $status_id;


	
	protected $project_id;


	
	protected $obj_type;


	
	protected $obj_id;


	
	protected $uid;


	
	protected $name;


	
	protected $url;


	
	protected $priority;


	
	protected $uname;


	
	protected $banner_type;


	
	protected $file_type;


	
	protected $total_views;


	
	protected $total_clicks;


	
	protected $updated_at;


	
	protected $created_at;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getStatusId()
	{

		return $this->status_id;
	}

	
	public function getProjectId()
	{

		return $this->project_id;
	}

	
	public function getObjType()
	{

		return $this->obj_type;
	}

	
	public function getObjId()
	{

		return $this->obj_id;
	}

	
	public function getUid()
	{

		return $this->uid;
	}

	
	public function getName()
	{

		return $this->name;
	}

	
	public function getUrl()
	{

		return $this->url;
	}

	
	public function getPriority()
	{

		return $this->priority;
	}

	
	public function getUname()
	{

		return $this->uname;
	}

	
	public function getBannerType()
	{

		return $this->banner_type;
	}

	
	public function getFileType()
	{

		return $this->file_type;
	}

	
	public function getTotalViews()
	{

		return $this->total_views;
	}

	
	public function getTotalClicks()
	{

		return $this->total_clicks;
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = BannerItemPeer::ID;
		}

	} 
	
	public function setUserId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = BannerItemPeer::USER_ID;
		}

	} 
	
	public function setStatusId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->status_id !== $v) {
			$this->status_id = $v;
			$this->modifiedColumns[] = BannerItemPeer::STATUS_ID;
		}

	} 
	
	public function setProjectId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->project_id !== $v) {
			$this->project_id = $v;
			$this->modifiedColumns[] = BannerItemPeer::PROJECT_ID;
		}

	} 
	
	public function setObjType($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->obj_type !== $v) {
			$this->obj_type = $v;
			$this->modifiedColumns[] = BannerItemPeer::OBJ_TYPE;
		}

	} 
	
	public function setObjId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->obj_id !== $v) {
			$this->obj_id = $v;
			$this->modifiedColumns[] = BannerItemPeer::OBJ_ID;
		}

	} 
	
	public function setUid($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->uid !== $v) {
			$this->uid = $v;
			$this->modifiedColumns[] = BannerItemPeer::UID;
		}

	} 
	
	public function setName($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->name !== $v) {
			$this->name = $v;
			$this->modifiedColumns[] = BannerItemPeer::NAME;
		}

	} 
	
	public function setUrl($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->url !== $v) {
			$this->url = $v;
			$this->modifiedColumns[] = BannerItemPeer::URL;
		}

	} 
	
	public function setPriority($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->priority !== $v) {
			$this->priority = $v;
			$this->modifiedColumns[] = BannerItemPeer::PRIORITY;
		}

	} 
	
	public function setUname($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->uname !== $v) {
			$this->uname = $v;
			$this->modifiedColumns[] = BannerItemPeer::UNAME;
		}

	} 
	
	public function setBannerType($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->banner_type !== $v) {
			$this->banner_type = $v;
			$this->modifiedColumns[] = BannerItemPeer::BANNER_TYPE;
		}

	} 
	
	public function setFileType($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->file_type !== $v) {
			$this->file_type = $v;
			$this->modifiedColumns[] = BannerItemPeer::FILE_TYPE;
		}

	} 
	
	public function setTotalViews($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->total_views !== $v) {
			$this->total_views = $v;
			$this->modifiedColumns[] = BannerItemPeer::TOTAL_VIEWS;
		}

	} 
	
	public function setTotalClicks($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->total_clicks !== $v) {
			$this->total_clicks = $v;
			$this->modifiedColumns[] = BannerItemPeer::TOTAL_CLICKS;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = BannerItemPeer::UPDATED_AT;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = BannerItemPeer::CREATED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->user_id = $rs->getInt($startcol + 1);

			$this->status_id = $rs->getInt($startcol + 2);

			$this->project_id = $rs->getInt($startcol + 3);

			$this->obj_type = $rs->getInt($startcol + 4);

			$this->obj_id = $rs->getInt($startcol + 5);

			$this->uid = $rs->getString($startcol + 6);

			$this->name = $rs->getString($startcol + 7);

			$this->url = $rs->getString($startcol + 8);

			$this->priority = $rs->getInt($startcol + 9);

			$this->uname = $rs->getString($startcol + 10);

			$this->banner_type = $rs->getInt($startcol + 11);

			$this->file_type = $rs->getString($startcol + 12);

			$this->total_views = $rs->getInt($startcol + 13);

			$this->total_clicks = $rs->getInt($startcol + 14);

			$this->updated_at = $rs->getTimestamp($startcol + 15, null);

			$this->created_at = $rs->getTimestamp($startcol + 16, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 17; 
		} catch (Exception $e) {
			throw new PropelException("Error populating BannerItem object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(BannerItemPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			BannerItemPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isModified() && !$this->isColumnModified(BannerItemPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

    if ($this->isNew() && !$this->isColumnModified(BannerItemPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(BannerItemPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = BannerItemPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += BannerItemPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = BannerItemPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = BannerItemPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getUserId();
				break;
			case 2:
				return $this->getStatusId();
				break;
			case 3:
				return $this->getProjectId();
				break;
			case 4:
				return $this->getObjType();
				break;
			case 5:
				return $this->getObjId();
				break;
			case 6:
				return $this->getUid();
				break;
			case 7:
				return $this->getName();
				break;
			case 8:
				return $this->getUrl();
				break;
			case 9:
				return $this->getPriority();
				break;
			case 10:
				return $this->getUname();
				break;
			case 11:
				return $this->getBannerType();
				break;
			case 12:
				return $this->getFileType();
				break;
			case 13:
				return $this->getTotalViews();
				break;
			case 14:
				return $this->getTotalClicks();
				break;
			case 15:
				return $this->getUpdatedAt();
				break;
			case 16:
				return $this->getCreatedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = BannerItemPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getUserId(),
			$keys[2] => $this->getStatusId(),
			$keys[3] => $this->getProjectId(),
			$keys[4] => $this->getObjType(),
			$keys[5] => $this->getObjId(),
			$keys[6] => $this->getUid(),
			$keys[7] => $this->getName(),
			$keys[8] => $this->getUrl(),
			$keys[9] => $this->getPriority(),
			$keys[10] => $this->getUname(),
			$keys[11] => $this->getBannerType(),
			$keys[12] => $this->getFileType(),
			$keys[13] => $this->getTotalViews(),
			$keys[14] => $this->getTotalClicks(),
			$keys[15] => $this->getUpdatedAt(),
			$keys[16] => $this->getCreatedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = BannerItemPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setUserId($value);
				break;
			case 2:
				$this->setStatusId($value);
				break;
			case 3:
				$this->setProjectId($value);
				break;
			case 4:
				$this->setObjType($value);
				break;
			case 5:
				$this->setObjId($value);
				break;
			case 6:
				$this->setUid($value);
				break;
			case 7:
				$this->setName($value);
				break;
			case 8:
				$this->setUrl($value);
				break;
			case 9:
				$this->setPriority($value);
				break;
			case 10:
				$this->setUname($value);
				break;
			case 11:
				$this->setBannerType($value);
				break;
			case 12:
				$this->setFileType($value);
				break;
			case 13:
				$this->setTotalViews($value);
				break;
			case 14:
				$this->setTotalClicks($value);
				break;
			case 15:
				$this->setUpdatedAt($value);
				break;
			case 16:
				$this->setCreatedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = BannerItemPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setUserId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setStatusId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setProjectId($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setObjType($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setObjId($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setUid($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setName($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setUrl($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setPriority($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setUname($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setBannerType($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setFileType($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setTotalViews($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setTotalClicks($arr[$keys[14]]);
		if (array_key_exists($keys[15], $arr)) $this->setUpdatedAt($arr[$keys[15]]);
		if (array_key_exists($keys[16], $arr)) $this->setCreatedAt($arr[$keys[16]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(BannerItemPeer::DATABASE_NAME);

		if ($this->isColumnModified(BannerItemPeer::ID)) $criteria->add(BannerItemPeer::ID, $this->id);
		if ($this->isColumnModified(BannerItemPeer::USER_ID)) $criteria->add(BannerItemPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(BannerItemPeer::STATUS_ID)) $criteria->add(BannerItemPeer::STATUS_ID, $this->status_id);
		if ($this->isColumnModified(BannerItemPeer::PROJECT_ID)) $criteria->add(BannerItemPeer::PROJECT_ID, $this->project_id);
		if ($this->isColumnModified(BannerItemPeer::OBJ_TYPE)) $criteria->add(BannerItemPeer::OBJ_TYPE, $this->obj_type);
		if ($this->isColumnModified(BannerItemPeer::OBJ_ID)) $criteria->add(BannerItemPeer::OBJ_ID, $this->obj_id);
		if ($this->isColumnModified(BannerItemPeer::UID)) $criteria->add(BannerItemPeer::UID, $this->uid);
		if ($this->isColumnModified(BannerItemPeer::NAME)) $criteria->add(BannerItemPeer::NAME, $this->name);
		if ($this->isColumnModified(BannerItemPeer::URL)) $criteria->add(BannerItemPeer::URL, $this->url);
		if ($this->isColumnModified(BannerItemPeer::PRIORITY)) $criteria->add(BannerItemPeer::PRIORITY, $this->priority);
		if ($this->isColumnModified(BannerItemPeer::UNAME)) $criteria->add(BannerItemPeer::UNAME, $this->uname);
		if ($this->isColumnModified(BannerItemPeer::BANNER_TYPE)) $criteria->add(BannerItemPeer::BANNER_TYPE, $this->banner_type);
		if ($this->isColumnModified(BannerItemPeer::FILE_TYPE)) $criteria->add(BannerItemPeer::FILE_TYPE, $this->file_type);
		if ($this->isColumnModified(BannerItemPeer::TOTAL_VIEWS)) $criteria->add(BannerItemPeer::TOTAL_VIEWS, $this->total_views);
		if ($this->isColumnModified(BannerItemPeer::TOTAL_CLICKS)) $criteria->add(BannerItemPeer::TOTAL_CLICKS, $this->total_clicks);
		if ($this->isColumnModified(BannerItemPeer::UPDATED_AT)) $criteria->add(BannerItemPeer::UPDATED_AT, $this->updated_at);
		if ($this->isColumnModified(BannerItemPeer::CREATED_AT)) $criteria->add(BannerItemPeer::CREATED_AT, $this->created_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(BannerItemPeer::DATABASE_NAME);

		$criteria->add(BannerItemPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setUserId($this->user_id);

		$copyObj->setStatusId($this->status_id);

		$copyObj->setProjectId($this->project_id);

		$copyObj->setObjType($this->obj_type);

		$copyObj->setObjId($this->obj_id);

		$copyObj->setUid($this->uid);

		$copyObj->setName($this->name);

		$copyObj->setUrl($this->url);

		$copyObj->setPriority($this->priority);

		$copyObj->setUname($this->uname);

		$copyObj->setBannerType($this->banner_type);

		$copyObj->setFileType($this->file_type);

		$copyObj->setTotalViews($this->total_views);

		$copyObj->setTotalClicks($this->total_clicks);

		$copyObj->setUpdatedAt($this->updated_at);

		$copyObj->setCreatedAt($this->created_at);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new BannerItemPeer();
		}
		return self::$peer;
	}

} 